package di;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ZhangFei {

    private String name="张飞";
    //@Autowired注解翻译为自动装配
    // 表示当前这个属性会自动从Spring容器中找到合适的对象赋值
    // 当然,没有合适对象或有多个合适对象但没有匹配id时也会报错
    // 这里的匹配规则是属性名称和Spring容器中id匹配
    @Autowired
    private SnakeLance snakeLance;

    public void fight(){
        System.out.println(name+"使用"+snakeLance+"战斗");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public SnakeLance getSnakeLance() {
        return snakeLance;
    }

    public void setSnakeLance(SnakeLance snakeLance) {
        this.snakeLance = snakeLance;
    }
}
